﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OrderProcess
{
    public static class OrderDiscount
    {
        public static decimal ComputeDiscount(Order o, decimal total)
        {
            int count = 0;
            foreach (OrderItem i in o.Items)
            {
                count += i.Quantity;
            }
            decimal pct = 0;
            if (total > 500)
                pct = 0.20M;
            else if (total > 200)
                pct = 0.15M;
            else if (total > 100)
                pct = 0.10M;
            decimal discount = total * pct;
            discount -= (decimal)count;
            if (discount < 0)
                discount = 0;
            Console.WriteLine("Discount computed:${0}", discount.ToString());
            return discount;
        }
    }
}
